package com.xnewtech.xplatform.swan.mtm.modular.modname.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import com.xnewtech.xplatform.swan.model.page.PageResult;
import com.xnewtech.xplatform.swan.model.web.response.ResponseData;
import com.xnewtech.xplatform.swan.mtm.modular.modname.model.params.TestDemoParam;
import com.xnewtech.xplatform.swan.mtm.modular.modname.model.result.TestDemoResult;
import com.xnewtech.xplatform.swan.mtm.modular.modname.service.TestDemoService;
import com.xnewtech.xplatform.swan.libs.scanner.annotation.PostResource;
import com.xnewtech.xplatform.swan.libs.scanner.stereotype.ApiResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * demo表控制器
 *
 * @author xnew
 * @Date 2020-11-26 14:28:34
 */
@RestController
@ApiResource(name = "demo表管理", path = "/testDemo")
@Api(tags = "demo表")
public class TestDemoController {


    @Autowired
    private TestDemoService testDemoService;

    /**
     * 新增
     *
     * @author xnew
     * @Date 2020-11-26
     */
    @PostResource(name = "添加", path = "/add")
    @ApiOperation("新增")
    public ResponseData add(@RequestBody TestDemoParam param) {
        testDemoService.add(param);
        return ResponseData.success();
    }

    /**
     * 修改
     *
     * @author xnew
     * @Date 2020-11-26
     */
    @PostResource(name = "修改", path = "/update")
    @ApiOperation("修改")
    public ResponseData update(@RequestBody TestDemoParam param) {
        testDemoService.update(param);
        return ResponseData.success();
    }

    /**
     * 删除
     *
     * @author xnew
     * @Date 2020-11-26
     */
    @PostResource(name = "删除", path = "/delete")
    @ApiOperation("删除")
    public ResponseData delete(@RequestBody TestDemoParam param) {
        testDemoService.delete(param);
        return ResponseData.success();
    }

    /**
     * 查询单条详情
     *
     * @author xnew
     * @Date 2020-11-26
     */
    @PostResource(name = "查询详情", path = "/queryDetail")
    @ApiOperation(value = "查询详情", response = TestDemoResult.class)
    public ResponseData queryDetail(@RequestBody TestDemoParam param) {
        TestDemoResult result = testDemoService.findBySpec(param);
        return ResponseData.success(result);
    }

    /**
     * 查询列表
     *
     * @author xnew
     * @Date 2020-11-26
     */
    @PostResource(name = "查询列表", path = "/queryList")
    @ApiOperation(value = "查询列表", response = TestDemoResult.class)
    public ResponseData queryList(@RequestBody TestDemoParam param) {
        List<TestDemoResult> listBySpec = testDemoService.findListBySpec(param);
        return ResponseData.success(listBySpec);
    }

    /**
     * 分页查询列表
     *
     * @author xnew
     * @Date 2020-11-26
     */
    @PostResource(name = "分页查询列表", path = "/queryListPage")
    @ApiOperation(value = "分页查询列表", response = TestDemoResult.class)
    public ResponseData queryListPage(@RequestBody TestDemoParam param) {
        PageResult<TestDemoResult> pageBySpec = testDemoService.findPageBySpec(param);
        return ResponseData.success(pageBySpec);
    }

}
